package org.vaadin.golfscoretracker.data;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;

import org.vaadin.appfoundation.i18n.FieldTranslation;
import org.vaadin.appfoundation.persistence.data.AbstractPojo;

@Entity
public class Course extends AbstractPojo {

    private static final long serialVersionUID = -5550659841497630887L;

    @FieldTranslation(tuid = "course name")
    private String name;

    @FieldTranslation(tuid = "course holes")
    @OneToMany(mappedBy = "course", cascade = CascadeType.ALL)
    @OrderColumn(name = "hole")
    private List<Hole> holes = new ArrayList<Hole>();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Hole> getHoles() {
        return holes;
    }

    public void setHoles(List<Hole> holes) {
        this.holes = holes;
    }

    public void addHole(Hole hole) {
        if (hole != null) {
            getHoles().add(hole);
        }
    }

    public void removeHole(Hole hole) {
        if (hole != null) {
            getHoles().remove(hole);
        }
    }

}
